<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>一、初识JavaScript | HJ BLOG</title><meta name="keywords" content="JavaScript"><meta name="author" content="娄豪杰"><meta name="copyright" content="娄豪杰"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="JavaScript 基础语法 HTML ：标记语言 JavaScript ：编程语言  序言JavaScript（师傅领进门修行靠个人，出山了）1234(1)借鉴C语言的基本语法(2)借鉴Java语言的数据类型和内存管理(3)借鉴Scheme语言，将函数提升到&quot;第一等公民&quot;(first class)的地位(4)借鉴Self语言，使用基于原型(prototype)的继承机制 J">
<meta property="og:type" content="article">
<meta property="og:title" content="一、初识JavaScript">
<meta property="og:url" content="http://example.com/article/23cb5f5f.html">
<meta property="og:site_name" content="HJ BLOG">
<meta property="og:description" content="JavaScript 基础语法 HTML ：标记语言 JavaScript ：编程语言  序言JavaScript（师傅领进门修行靠个人，出山了）1234(1)借鉴C语言的基本语法(2)借鉴Java语言的数据类型和内存管理(3)借鉴Scheme语言，将函数提升到&quot;第一等公民&quot;(first class)的地位(4)借鉴Self语言，使用基于原型(prototype)的继承机制 J">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&refer=http%3A%2F%2Fpic1.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645530798&t=e5c6ac493d1c8b04cd2a4740e1cc9870">
<meta property="article:published_time" content="2019-02-28T16:00:00.000Z">
<meta property="article:modified_time" content="2022-01-23T11:53:58.151Z">
<meta property="article:author" content="娄豪杰">
<meta property="article:tag" content="JavaScript">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&refer=http%3A%2F%2Fpic1.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645530798&t=e5c6ac493d1c8b04cd2a4740e1cc9870"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/article/23cb5f5f"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '一、初识JavaScript',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-01-23 19:53:58'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/static-butterfly/dist/css/index.min.css"><link rel="stylesheet" href="/css/custom.css"><meta name="generator" content="Hexo 5.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">70</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">23</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">17</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fa fa-book"></i><span> 阅读</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fa fa-bars"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photo"><i class="fa-fw fas fa-image"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa-fw fas fa-heart card-announcement-animation"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&amp;refer=http%3A%2F%2Fpic1.zhimg.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1645530798&amp;t=e5c6ac493d1c8b04cd2a4740e1cc9870')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">HJ BLOG</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fa fa-book"></i><span> 阅读</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fa fa-bars"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photo"><i class="fa-fw fas fa-image"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa-fw fas fa-heart card-announcement-animation"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">一、初识JavaScript</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-02-28T16:00:00.000Z" title="发表于 2019-03-01 00:00:00">2019-03-01</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-01-23T11:53:58.151Z" title="更新于 2022-01-23 19:53:58">2022-01-23</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/JavaScript/">JavaScript</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="一、初识JavaScript"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="JavaScript-基础语法"><a href="#JavaScript-基础语法" class="headerlink" title="JavaScript 基础语法"></a>JavaScript 基础语法</h1><ul>
<li><code>HTML</code> ：标记语言</li>
<li><code>JavaScript</code> ：编程语言</li>
</ul>
<h2 id="序言"><a href="#序言" class="headerlink" title="序言"></a>序言</h2><h3 id="JavaScript（师傅领进门修行靠个人，出山了）"><a href="#JavaScript（师傅领进门修行靠个人，出山了）" class="headerlink" title="JavaScript（师傅领进门修行靠个人，出山了）"></a>JavaScript（师傅领进门修行靠个人，出山了）</h3><figure class="highlight txt"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">(1)借鉴C语言的基本语法</span><br><span class="line">(2)借鉴Java语言的数据类型和内存管理</span><br><span class="line">(3)借鉴Scheme语言，将函数提升到&quot;第一等公民&quot;(first class)的地位</span><br><span class="line">(4)借鉴Self语言，使用基于原型(prototype)的继承机制</span><br></pre></td></tr></table></figure>
<h3 id="JavaScript-的组成ECMAScript-BOM-DOM"><a href="#JavaScript-的组成ECMAScript-BOM-DOM" class="headerlink" title="JavaScript 的组成ECMAScript+BOM+DOM"></a>JavaScript 的组成<code>ECMAScript</code>+<code>BOM</code>+<code>DOM</code></h3><figure class="highlight txt"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1. ECMASCRIPT: 语法规范</span><br><span class="line">2. BOM: 浏览器对象模型</span><br><span class="line">   &#123; 有一套成熟的可以操作浏览器的 API，通过 BOM 可以操作浏览器 &#125;</span><br><span class="line">3. DOM (Document Object Model): 文档对象模型</span><br><span class="line">   &#123; 有一套成熟的可以操作页面元素的 API，通过 DOM 可以操作页面中的元素 &#125;</span><br></pre></td></tr></table></figure>
<h2 id="JS-中什么是变量"><a href="#JS-中什么是变量" class="headerlink" title="JS 中什么是变量?"></a>JS 中什么是变量?</h2><ul>
<li>变量指的是在程序中保存数据的一个容器</li>
<li>变量是计算机内存中存储数据的标识符，根据变量名称可以获取到内存中存储的数据</li>
<li>也就是说，我们向内存中存储了一个数据，然后要给这个数据起一个名字，为了是我们以后再次找到他</li>
<li>语法： <code>var 变量名 = 值</code></li>
</ul>
<h3 id="定义变量及赋值小栗子："><a href="#定义变量及赋值小栗子：" class="headerlink" title="定义变量及赋值小栗子："></a>定义变量及赋值小栗子：</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 场景一：先定义后赋值 */</span></span><br><span class="line"><span class="keyword">var</span> num1;</span><br><span class="line">num1 = <span class="number">100</span>;</span><br><span class="line"><span class="built_in">console</span>.log(num1); <span class="comment">// 100</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* 场景二：变量定义并且赋值 */</span></span><br><span class="line"><span class="keyword">var</span> num2 = <span class="number">100</span>;</span><br><span class="line"><span class="built_in">console</span>.log(num2); <span class="comment">// 100</span></span><br></pre></td></tr></table></figure>
<ul>
<li>注意：<ol>
<li>一个变量名只能存储一个值</li>
<li>当再次给一个变量赋值的时候，前面一次的值就没有了</li>
<li>变量名称区分大小写（<code>JS</code> 严格区分大小写）</li>
</ol>
</li>
</ul>
<h3 id="变量的命名规则和命名规范"><a href="#变量的命名规则和命名规范" class="headerlink" title="变量的命名规则和命名规范"></a>变量的命名规则和命名规范</h3><ul>
<li>规则： 必须遵守的，不遵守就是错<ol>
<li>一个变量名称可以由 <strong>数字</strong>、<strong>字母</strong>、<strong>英文下划线（_）</strong>、<strong>美元符号（$）</strong> 组成</li>
<li>严格区分大小写</li>
<li>不能由数字开头，不要使用中文汉字命名</li>
<li>不能是 <strong>保留字</strong> 或者 <strong>关键字</strong></li>
<li>不要出现空格</li>
</ol>
</li>
<li>规范： 建议遵守的（开发者默认），不遵守不会报错<ol>
<li>变量名尽量有意义（语义化）</li>
<li>遵循驼峰命名规则，由多个单词组成的时候，从第二个单词开始首字母大写</li>
</ol>
</li>
</ul>
<h2 id="数据类型（重点）"><a href="#数据类型（重点）" class="headerlink" title="数据类型（重点）"></a>数据类型（重点）</h2><ul>
<li>是指我们存储在内存中的数据的类型</li>
<li>我们通常分为两大类 <strong>基本数据类型</strong> 和 <strong>引用数据类型</strong></li>
</ul>
<h3 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h3><ol>
<li>数值类型（number）<ul>
<li>一切数字都是数值类型（包括二进制，十进制，十六进制等）</li>
<li><code>NaN</code>（not a number），一个非数字</li>
</ul>
</li>
<li>字符串类型（string）<ul>
<li>被引号包裹的所有内容（可以是单引号也可以是双引号）</li>
</ul>
</li>
<li>布尔类型（boolean）<ul>
<li>只有两个（<code>true</code> 或者 <code>false</code>）</li>
</ul>
</li>
<li>null 类型（null）<ul>
<li>只有一个，就是 <code>null</code>，表示空的意思</li>
</ul>
</li>
<li>undefined 类型（undefined）<ul>
<li>只有一个，就是 <code>undefined</code>，表示没有值的意思</li>
</ul>
</li>
</ol>
<h3 id="引用数据类型"><a href="#引用数据类型" class="headerlink" title="引用数据类型"></a>引用数据类型</h3><ol>
<li>引用数据类型也就是对象数据类型 object，比如：<code>object</code>、<code>array</code>、<code>function</code>等；</li>
</ol>
<h2 id="判断数据类型"><a href="#判断数据类型" class="headerlink" title="判断数据类型"></a>判断数据类型</h2><ul>
<li>既然已经把数据分开了类型，那么我们就要知道我们存储的数据是一个什么类型的数据</li>
<li>使用 <code>typeof</code> 关键字来进行判断（默认以字符串形式）</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 第一种使用方式 */</span></span><br><span class="line"><span class="keyword">var</span> num = <span class="number">100</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> num); <span class="comment">// number</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* 第二种使用方式 */</span></span><br><span class="line"><span class="keyword">var</span> str = <span class="string">&quot;HJ&quot;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> str); <span class="comment">// string</span></span><br></pre></td></tr></table></figure>
<h3 id="判断一个变量是不是数字，不是的话返回-true"><a href="#判断一个变量是不是数字，不是的话返回-true" class="headerlink" title="判断一个变量是不是数字，不是的话返回 true"></a>判断一个变量是不是数字，不是的话返回 true</h3><ul>
<li>可以使用 <code>isNaN</code> 这个方法来判断一个变量是不是数字</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 如果变量是一个数字 */</span></span><br><span class="line"><span class="keyword">var</span> num = <span class="number">100</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">isNaN</span>(num)); <span class="comment">//false</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* 如果变量不是一个数字 */</span></span><br><span class="line"><span class="keyword">var</span> name = <span class="string">&quot;HJ&quot;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">isNaN</span>(name)); <span class="comment">//true</span></span><br></pre></td></tr></table></figure>
<h2 id="数据类型转换"><a href="#数据类型转换" class="headerlink" title="数据类型转换"></a>数据类型转换</h2><ul>
<li>数据类型之间的转换，比如数字转成字符串，字符串转成布尔，布尔转成数字等</li>
</ul>
<h3 id="其他数据类型转成数值"><a href="#其他数据类型转成数值" class="headerlink" title="其他数据类型转成数值"></a>其他数据类型转成数值</h3><ol>
<li><p><code>Number(变量)</code></p>
<ul>
<li>可以把一个变量强制转换成数值类型</li>
<li>可以转换小数，会保留小数</li>
<li>可以转换布尔值</li>
<li>遇到不可转换的都会返回 <code>NaN</code></li>
</ul>
</li>
<li><p><code>parseInt(变量)</code></p>
<ul>
<li>从第一位开始检查，是数字就转换，直到一个不是数字的内容</li>
<li>开头就不是数字，那么直接返回 <code>NaN</code></li>
<li>不认识小数点，只能保留整数</li>
</ul>
</li>
<li><p><code>parseFloat(变量)</code></p>
<ul>
<li>从第一位开始检查，是数字就转换，直到一个不是数字的内容</li>
<li>开头就不是数字，那么直接返回 <code>NaN</code></li>
<li>认识一次小数点</li>
</ul>
</li>
<li><p>除了加法以外的数学运算</p>
<ul>
<li>运算符两边都是可运算数字才行</li>
<li>如果运算符任何一边不是一个可运算数字，那么就会返回 <code>NaN</code></li>
<li>加法不可以用</li>
</ul>
</li>
</ol>
<h3 id="其他数据类型转成字符串"><a href="#其他数据类型转成字符串" class="headerlink" title="其他数据类型转成字符串"></a>其他数据类型转成字符串</h3><ol>
<li><code>变量.toString()</code><ul>
<li>有一些数据类型不能使用 <code>toString()</code> 方法，比如 <code>undefined</code> 和 <code>null</code></li>
</ul>
</li>
<li><code>String(变量)</code><ul>
<li>所有数据类型都可以</li>
</ul>
</li>
<li>使用加法运算<ul>
<li>在 JS 里面，<code>+</code> 由两个含义</li>
<li>字符串拼接： 只要 <code>+</code> 任意一边是字符串，就会进行字符串拼接</li>
<li>加法运算：只有 <code>+</code> 两边都是数字的时候，才会进行数学运算</li>
</ul>
</li>
</ol>
<h3 id="其他数据类型转成布尔"><a href="#其他数据类型转成布尔" class="headerlink" title="其他数据类型转成布尔"></a>其他数据类型转成布尔</h3><ol>
<li><code>Boolean(变量)</code><ul>
<li>在 js 中，只有 <code>&#39;&#39;</code>、<code>0</code>、<code>null</code>、<code>undefined</code>、<code>NaN</code>，这些是 <code>false</code>，其余都是 <code>true</code></li>
</ul>
</li>
</ol>
<h2 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h2><ul>
<li>就是在代码里面进行运算的时候使用的符号，不光只是数学运算，我们在 <code>js</code> 里面还有很多的运算方式</li>
</ul>
<h3 id="数学运算符"><a href="#数学运算符" class="headerlink" title="数学运算符"></a>数学运算符</h3><ol>
<li><p><code>+</code></p>
<ul>
<li>只有符号两边都是数字的时候才会进行加法运算</li>
<li>只要符号任意一边是字符串类型，就会进行字符串拼接</li>
</ul>
</li>
<li><p><code>-</code></p>
<ul>
<li>会执行减法运算</li>
<li>会自动把两边都转换成数字进行运算</li>
</ul>
</li>
<li><p><code>*</code></p>
<ul>
<li>会执行乘法运算</li>
<li>会自动把两边都转换成数字进行运算</li>
</ul>
</li>
<li><p><code>/</code></p>
<ul>
<li>会执行除法运算</li>
<li>会自动把两边都转换成数字进行运算</li>
</ul>
</li>
<li><p><code>%</code></p>
<ul>
<li>会执行取余运算</li>
<li>会自动把两边都转换成数字进行运算</li>
</ul>
</li>
<li><p><code>**</code></p>
<ul>
<li>求次方</li>
<li>栗子：2**3 = 2x2x2 = 8</li>
</ul>
</li>
</ol>
<h3 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</h3><ol>
<li><p><code>=</code></p>
<ul>
<li>就是把 <code>=</code> 右边的赋值给等号左边的变量名</li>
<li><code>var num = 100</code></li>
<li>就是把 100 赋值给 num 变量</li>
<li>那么 num 变量的值就是 100</li>
</ul>
</li>
<li><p><code>+=</code></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line">num += <span class="number">10</span>;</span><br><span class="line"><span class="built_in">console</span>.log(num); <span class="comment">// 20</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>a += 10</code> 等价于 <code>a = a + 10</code></li>
</ul>
</li>
<li><p><code>-=</code></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line">num -= <span class="number">10</span>;</span><br><span class="line"><span class="built_in">console</span>.log(num); <span class="comment">// 0</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>a -= 10</code> 等价于 <code>a = a - 10</code></li>
</ul>
</li>
<li><p><code>*=</code></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line">num *= <span class="number">10</span>;</span><br><span class="line"><span class="built_in">console</span>.log(num); <span class="comment">// 100</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>a *= 10</code> 等价于 <code>a = a * 10</code></li>
</ul>
</li>
<li><p><code>/=</code></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line">num /= <span class="number">10</span>;</span><br><span class="line"><span class="built_in">console</span>.log(num); <span class="comment">// 1</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>a /= 10</code> 等价于 <code>a = a / 10</code></li>
</ul>
</li>
<li><p><code>%=</code></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line">num %= <span class="number">10</span>;</span><br><span class="line"><span class="built_in">console</span>.log(num); <span class="comment">// 0</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>a %= 10</code> 等价于 <code>a = a % 10</code></li>
</ul>
</li>
</ol>
<h3 id="比较运算符"><a href="#比较运算符" class="headerlink" title="比较运算符"></a>比较运算符</h3><ol>
<li><code>==</code><ul>
<li>比较符号两边的值是否相等，不管数据类型</li>
<li><code>1 == &#39;1&#39;</code></li>
<li>两个的值是一样的，所以得到 <code>true</code></li>
</ul>
</li>
<li><code>===</code><ul>
<li>比较符号两边的值和数据类型是否都相等</li>
<li><code>1 === &#39;1&#39;</code></li>
<li>两个值虽然一样，但是因为数据类型不一样，所以得到 <code>false</code></li>
</ul>
</li>
<li><code>!=</code><ul>
<li>比较符号两边的值是否不等</li>
<li><code>1 != &#39;1&#39;</code></li>
<li>因为两边的值是相等的，所以比较他们不等的时候得到 <code>false</code></li>
</ul>
</li>
<li><code>!==</code><ul>
<li>比较符号两边的数据类型和值是否不等</li>
<li><code>1 !== &#39;1&#39;</code></li>
<li>因为两边的数据类型确实不一样，所以得到 <code>true</code></li>
</ul>
</li>
<li><code>&gt;=</code><ul>
<li>比较左边的值是否 <strong>大于或等于</strong> 右边的值</li>
<li><code>1 &gt;= 1</code> 结果是 <code>true</code></li>
<li><code>1 &gt;= 0</code> 结果是 <code>true</code></li>
<li><code>1 &gt;= 2</code> 结果是 <code>false</code></li>
</ul>
</li>
<li><code>&lt;=</code><ul>
<li>比较左边的值是否 <strong>小于或等于</strong> 右边的值</li>
<li><code>1 &lt;= 2</code> 结果是 <code>true</code></li>
<li><code>1 &lt;= 1</code> 结果是 <code>true</code></li>
<li><code>1 &lt;= 0</code> 结果是 <code>false</code></li>
</ul>
</li>
<li><code>&gt;</code><ul>
<li>比较左边的值是否 <strong>大于</strong> 右边的值</li>
<li><code>1 &gt; 0</code> 结果是 <code>true</code></li>
<li><code>1 &gt; 1</code> 结果是 <code>false</code></li>
<li><code>1 &gt; 2</code> 结果是 <code>false</code></li>
</ul>
</li>
<li><code>&lt;</code><ul>
<li>比较左边的值是否 <strong>小于</strong> 右边的值</li>
<li><code>1 &lt; 2</code> 结果是 <code>true</code></li>
<li><code>1 &lt; 1</code> 结果是 <code>false</code></li>
<li><code>1 &lt; 0</code> 结果是 <code>false</code></li>
</ul>
</li>
</ol>
<h3 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h3><ol>
<li><code>&amp;&amp;</code><ul>
<li>进行 且 的运算</li>
<li>符号左边必须为 <code>true</code> 并且右边也是 <code>true</code>，才会返回 <code>true</code></li>
<li>只要有一边不是 <code>true</code>，那么就会返回 <code>false</code></li>
<li><code>true &amp;&amp; true</code> 结果是 <code>true</code></li>
<li><code>true &amp;&amp; false</code> 结果是 <code>false</code></li>
<li><code>false &amp;&amp; true</code> 结果是 <code>false</code></li>
<li><code>false &amp;&amp; false</code> 结果是 <code>false</code></li>
</ul>
</li>
<li><code>||</code><ul>
<li>进行 或 的运算</li>
<li>符号的左边为 <code>true</code> 或者右边为 <code>true</code>，都会返回 <code>true</code></li>
<li>只有两边都是 <code>false</code> 的时候才会返回 <code>false</code></li>
<li><code>true || true</code> 结果是 <code>true</code></li>
<li><code>true || false</code> 结果是 <code>true</code></li>
<li><code>false || true</code> 结果是 <code>true</code></li>
<li><code>false || false</code> 结果是 <code>false</code></li>
</ul>
</li>
<li><code>!</code><ul>
<li>进行 取反 运算</li>
<li>本身是 <code>true</code> 的，会变成 <code>false</code></li>
<li>本身是 <code>false</code> 的，会变成 <code>true</code></li>
<li><code>!true</code> 结果是 <code>false</code></li>
<li><code>!false</code> 结果是 <code>true</code></li>
</ul>
</li>
</ol>
<h3 id="自增自减运算符（一元运算符）"><a href="#自增自减运算符（一元运算符）" class="headerlink" title="自增自减运算符（一元运算符）"></a>自增自减运算符（一元运算符）</h3><ol>
<li><p><code>++</code></p>
<ul>
<li><p>进行自增运算</p>
</li>
<li><p>分成两种，<strong>前置++</strong> 和 <strong>后置++</strong></p>
</li>
<li><p>前置++，会先把值自动 +1，在返回</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line"><span class="built_in">console</span>.log(++num);</span><br><span class="line"><span class="comment">// 会返回 11，并且把 num 的值变成 11</span></span><br></pre></td></tr></table></figure></li>
<li><p>后置++，会先把值返回，在自动+1</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line"><span class="built_in">console</span>.log(num++);</span><br><span class="line"><span class="comment">// 会返回 10，然后把 a 的值变成 11</span></span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p><code>--</code></p>
<ul>
<li>进行自减运算</li>
<li>分成两种，<strong>前置–</strong> 和 <strong>后置–</strong></li>
<li>和 <code>++</code> 运算符道理一样</li>
</ul>
</li>
</ol>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">娄豪杰</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/article/23cb5f5f.html">http://example.com/article/23cb5f5f.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">HJ BLOG</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/JavaScript/">JavaScript</a></div><div class="post_share"><div class="social-share" data-image="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&amp;refer=http%3A%2F%2Fpic1.zhimg.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1645530798&amp;t=e5c6ac493d1c8b04cd2a4740e1cc9870" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/article/bdf08e07.html"><img class="prev-cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&amp;refer=http%3A%2F%2Fpic1.zhimg.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1645530798&amp;t=e5c6ac493d1c8b04cd2a4740e1cc9870" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">二、JS分支结构</div></div></a></div><div class="next-post pull-right"><a href="/article/8aacd75.html"><img class="next-cover" src="https://img0.baidu.com/it/u=895989097,3753061311&amp;fm=253&amp;fmt=auto&amp;app=120&amp;f=JPEG?w=650&amp;h=446" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">二、玩转HTML5&amp;CSS3新特性</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/article/4200b2b0.html" title="三、JS循环结构"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&refer=http%3A%2F%2Fpic1.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645530798&t=e5c6ac493d1c8b04cd2a4740e1cc9870" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-03-03</div><div class="title">三、JS循环结构</div></div></a></div><div><a href="/article/2c83c14b.html" title="四、JS函数（上）"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&refer=http%3A%2F%2Fpic1.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645530798&t=e5c6ac493d1c8b04cd2a4740e1cc9870" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-03-04</div><div class="title">四、JS函数（上）</div></div></a></div><div><a href="/article/bdf08e07.html" title="二、JS分支结构"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&refer=http%3A%2F%2Fpic1.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645530798&t=e5c6ac493d1c8b04cd2a4740e1cc9870" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-03-02</div><div class="title">二、JS分支结构</div></div></a></div><div><a href="/article/dcee35d7.html" title="五、JS函数（下）"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&refer=http%3A%2F%2Fpic1.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645530798&t=e5c6ac493d1c8b04cd2a4740e1cc9870" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-03-05</div><div class="title">五、JS函数（下）</div></div></a></div><div><a href="/article/23ec2cd1.html" title="六、JS数组[Array]"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&refer=http%3A%2F%2Fpic1.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645530798&t=e5c6ac493d1c8b04cd2a4740e1cc9870" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-03-06</div><div class="title">六、JS数组[Array]</div></div></a></div><div><a href="/article/e9ccd4a7.html" title="七、JS字符串"string""><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&refer=http%3A%2F%2Fpic1.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645530798&t=e5c6ac493d1c8b04cd2a4740e1cc9870" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-03-07</div><div class="title">七、JS字符串"string"</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">娄豪杰</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">70</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">23</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">17</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/louhaojie99"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">人生就像品茗，懂得吃苦，才能回甘啊。</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#JavaScript-%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95"><span class="toc-number">1.</span> <span class="toc-text">JavaScript 基础语法</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BA%8F%E8%A8%80"><span class="toc-number">1.1.</span> <span class="toc-text">序言</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#JavaScript%EF%BC%88%E5%B8%88%E5%82%85%E9%A2%86%E8%BF%9B%E9%97%A8%E4%BF%AE%E8%A1%8C%E9%9D%A0%E4%B8%AA%E4%BA%BA%EF%BC%8C%E5%87%BA%E5%B1%B1%E4%BA%86%EF%BC%89"><span class="toc-number">1.1.1.</span> <span class="toc-text">JavaScript（师傅领进门修行靠个人，出山了）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#JavaScript-%E7%9A%84%E7%BB%84%E6%88%90ECMAScript-BOM-DOM"><span class="toc-number">1.1.2.</span> <span class="toc-text">JavaScript 的组成ECMAScript+BOM+DOM</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#JS-%E4%B8%AD%E4%BB%80%E4%B9%88%E6%98%AF%E5%8F%98%E9%87%8F"><span class="toc-number">1.2.</span> <span class="toc-text">JS 中什么是变量?</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9A%E4%B9%89%E5%8F%98%E9%87%8F%E5%8F%8A%E8%B5%8B%E5%80%BC%E5%B0%8F%E6%A0%97%E5%AD%90%EF%BC%9A"><span class="toc-number">1.2.1.</span> <span class="toc-text">定义变量及赋值小栗子：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E7%9A%84%E5%91%BD%E5%90%8D%E8%A7%84%E5%88%99%E5%92%8C%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83"><span class="toc-number">1.2.2.</span> <span class="toc-text">变量的命名规则和命名规范</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%88%E9%87%8D%E7%82%B9%EF%BC%89"><span class="toc-number">1.3.</span> <span class="toc-text">数据类型（重点）</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.3.1.</span> <span class="toc-text">基本数据类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%95%E7%94%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.3.2.</span> <span class="toc-text">引用数据类型</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%A4%E6%96%AD%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.4.</span> <span class="toc-text">判断数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A4%E6%96%AD%E4%B8%80%E4%B8%AA%E5%8F%98%E9%87%8F%E6%98%AF%E4%B8%8D%E6%98%AF%E6%95%B0%E5%AD%97%EF%BC%8C%E4%B8%8D%E6%98%AF%E7%9A%84%E8%AF%9D%E8%BF%94%E5%9B%9E-true"><span class="toc-number">1.4.1.</span> <span class="toc-text">判断一个变量是不是数字，不是的话返回 true</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-number">1.5.</span> <span class="toc-text">数据类型转换</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%88%90%E6%95%B0%E5%80%BC"><span class="toc-number">1.5.1.</span> <span class="toc-text">其他数据类型转成数值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%88%90%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">1.5.2.</span> <span class="toc-text">其他数据类型转成字符串</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%88%90%E5%B8%83%E5%B0%94"><span class="toc-number">1.5.3.</span> <span class="toc-text">其他数据类型转成布尔</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">1.6.</span> <span class="toc-text">运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E5%AD%A6%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">1.6.1.</span> <span class="toc-text">数学运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B5%8B%E5%80%BC%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">1.6.2.</span> <span class="toc-text">赋值运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">1.6.3.</span> <span class="toc-text">比较运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">1.6.4.</span> <span class="toc-text">逻辑运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%A2%9E%E8%87%AA%E5%87%8F%E8%BF%90%E7%AE%97%E7%AC%A6%EF%BC%88%E4%B8%80%E5%85%83%E8%BF%90%E7%AE%97%E7%AC%A6%EF%BC%89"><span class="toc-number">1.6.5.</span> <span class="toc-text">自增自减运算符（一元运算符）</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/article/cc11b2b0.html" title="二、JavaScript设计模式【下】"><img src="https://picabstract-preview-ftn.weiyun.com/ftn_pic_abs_v3/983a2ddf4c01d0f319b391469f669eba7a1a82ba077da903e3114d4062c26cdea809b197d9cf02bb077af6272de8e1ed?pictype=scale&amp;from=30113&amp;version=3.3.3.3&amp;uin=851681631&amp;fname=12_js.jpg&amp;size=750" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="二、JavaScript设计模式【下】"/></a><div class="content"><a class="title" href="/article/cc11b2b0.html" title="二、JavaScript设计模式【下】">二、JavaScript设计模式【下】</a><time datetime="2021-09-11T16:00:00.000Z" title="发表于 2021-09-12 00:00:00">2021-09-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/cc00b2b0.html" title="一、JavaScript设计模式【上】"><img src="https://picabstract-preview-ftn.weiyun.com/ftn_pic_abs_v3/983a2ddf4c01d0f319b391469f669eba7a1a82ba077da903e3114d4062c26cdea809b197d9cf02bb077af6272de8e1ed?pictype=scale&amp;from=30113&amp;version=3.3.3.3&amp;uin=851681631&amp;fname=12_js.jpg&amp;size=750" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="一、JavaScript设计模式【上】"/></a><div class="content"><a class="title" href="/article/cc00b2b0.html" title="一、JavaScript设计模式【上】">一、JavaScript设计模式【上】</a><time datetime="2021-09-10T16:00:00.000Z" title="发表于 2021-09-11 00:00:00">2021-09-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/vue-sound-code10.html" title="十、Vue源码【内置组件篇】"><img src="https://img2.baidu.com/it/u=4067570870,2963075030&amp;fm=253&amp;fmt=auto&amp;app=120&amp;f=JPEG?w=640&amp;h=360" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="十、Vue源码【内置组件篇】"/></a><div class="content"><a class="title" href="/article/vue-sound-code10.html" title="十、Vue源码【内置组件篇】">十、Vue源码【内置组件篇】</a><time datetime="2021-09-09T16:00:00.000Z" title="发表于 2021-09-10 00:00:00">2021-09-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/vue-sound-code9.html" title="九、Vue源码【指令篇】"><img src="https://img2.baidu.com/it/u=4067570870,2963075030&amp;fm=253&amp;fmt=auto&amp;app=120&amp;f=JPEG?w=640&amp;h=360" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="九、Vue源码【指令篇】"/></a><div class="content"><a class="title" href="/article/vue-sound-code9.html" title="九、Vue源码【指令篇】">九、Vue源码【指令篇】</a><time datetime="2021-09-08T16:00:00.000Z" title="发表于 2021-09-09 00:00:00">2021-09-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/vue-sound-code8.html" title="八、Vue源码【过滤器篇】"><img src="https://img2.baidu.com/it/u=4067570870,2963075030&amp;fm=253&amp;fmt=auto&amp;app=120&amp;f=JPEG?w=640&amp;h=360" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="八、Vue源码【过滤器篇】"/></a><div class="content"><a class="title" href="/article/vue-sound-code8.html" title="八、Vue源码【过滤器篇】">八、Vue源码【过滤器篇】</a><time datetime="2021-09-07T16:00:00.000Z" title="发表于 2021-09-08 00:00:00">2021-09-08</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2Fv2-25182ac6197d798d6d8b22d3b0710cbf_1200x500.jpg&amp;refer=http%3A%2F%2Fpic1.zhimg.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1645530798&amp;t=e5c6ac493d1c8b04cd2a4740e1cc9870')"><div id="footer-wrap"><div class="copyright">&copy;2017 - 2022 By 娄豪杰</div><div class="footer_custom_text"><div>嗨，欢迎来到我的博客，希望能帮助到您！</div></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"></div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-show-text.min.js" data-mobile="false" data-text="富强,民主,文明,和谐,自由,平等,公正,法治" data-fontsize="15px" data-random="true" async="async"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = [
  'title',
  '#config-diff',
  '#body-wrap',
  '#rightside-config-hide',
  '#rightside-config-show',
  '.js-pjax'
]

if (false) {
  pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
}

var pjax = new Pjax({
  elements: 'a:not([target="_blank"]):not([href="/music/"]):not([href="/no-pjax/"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener toc scroll 
  window.removeEventListener('scroll', window.tocScrollFn)

  typeof preloader === 'object' && preloader.initLoading()
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // Analytics
  if (false) {
    MtaH5.pgv()
  }

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginModelPath":"assets/","model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":false},"log":false,"pluginJsPath":"lib/","pluginRootPath":"live2dw/","tagMode":false});</script></body></html>